import type { CreateCrudOptionsRet } from '@fast-crud/fast-crud';

import { ref } from 'vue';

import { DefTenantApi } from '#/api';
import { $t } from '#/locales';

export function createCrudOptions(): CreateCrudOptionsRet {
  const checkedRowKeys = ref<string[]>([]);

  return {
    checkedRowKeys,
    crudOptions: {
      actionbar: { buttons: { add: { show: false } } },
      request: { pageRequest: DefTenantApi.pageRequest },
      table: {
        striped: true,
        rowKey: 'id',
        rowSelection: {
          type: 'checkbox',
          checkedRowKeys,
          onChange: (changed: string[]) => {
            checkedRowKeys.value = changed;
          },
        },
      },
      rowHandle: { show: false },
      columns: {
        name: {
          column: {
            resizable: false,
          },
          title: $t('devOperation.tenant.defTenant.name'),
          type: 'text',
          search: { show: true },
        },
      },
    },
  };
}
